<% layout('/layouts/default.html', {title: '会员管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('会员管理')}
			</div>
			<div class="box-tools pull-right">
				<a href="javascript:void(0);" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
<!--				<a href="#" class="btn btn-default" id="btnExport" title="${text('导出')}"><i class="glyphicon glyphicon-export"></i> ${text('导出')}</a>-->
				<a href="${ctx}/storage/member/vip/list" class="btn btn-default" title="${text('预设VIP会员')}"><i class="fa fa-fw icon-menu"></i> ${text('预设VIP会员')}</a>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${member}" action="${ctx}/storage/member/listData" method="post" class="form-inline hide"
			data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
			<div class="form-group">
				<label class="control-label">${text('类型')}：</label>
				<div class="control-inline">
					<% var types = [{type:'小B'},{type:'直接用户'},{type:'间接用户'}]; %>
					<#form:select path="type" class="form-control" items="${types}" itemLabel="type" itemValue="type" blankOption="true" blankOptionLabel="全部用户"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">${text('手机号')}：</label>
				<div class="control-inline">
					<#form:input path="phone" maxlength="255" class="form-control width-120"/>
				</div>
			</div>
			<div class="form-group">
				<label class="control-label">${text('昵称')}：</label>
				<div class="control-inline">
					<#form:input path="nickName" maxlength="255" class="form-control width-120"/>
				</div>
			</div>
			<div class="form-group">
				<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
				<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
			</div>
		</#form:form>
		<table id="dataGrid"></table>
		<div id="dataGridPage"></div>
	</div>
</div>
</div>
<% } %>
<script>
	// 初始化DataGrid对象
	$('#dataGrid').dataGrid({
		searchForm: $("#searchForm"),
		columnModel: [
			{header:'${text("类型")}', name:'type', index:'a.type', width:150, align:"center"},
			{header:'${text("手机号")}', name:'phone', index:'a.phone', width:150, align:"center"},
			{header:'${text("昵称")}', name:'nickName', index:'a.nick_name', width:150, align:"left"},
			{header:'${text("注册时间")}', name:'createDate', index:'a.create_date', width:150, align:"center"},
			{header:'${text("操作")}', name:'actions', width:160, align:"center", sortable:false, title:false, formatter: function(val, obj, row, act){
				var actions = [];
				actions.push('<a href="javascript:void(0);" onclick="doAdjust(\''+row.id+'\',\''+row.type+'\')" title="${text("调整会员等级")}"><i class="icon-check"></i>调整</a>&nbsp;');
				return actions.join('');
			}}
		]
	});
</script>
<script>
	function doAdjust(memberId,type) {
		js.layer.open({
			type: 1,
			area: ['600px'],
			title: '${text("调整会员等级")}',
			resize: false,
			scrollbar: true,
			content: js.template('adjustTpl'),
			success: function(layero, index){
				layero.find('#type').val(type);
			},
			btn: ['<i class="fa fa-check"></i> ${text("调整")}',
				'<i class="fa fa-remove"></i> ${text("关闭")}'],
			btn1: function(index, layero){
				js.ajaxSubmit("${ctx}/storage/member/adjust",{
					memberId:memberId,
					type: layero.find('#type option:selected').val(),
				}, function(data){
					js.showMessage(data.message);
					if(data.result == Global.TRUE){
						window.location.reload();
					}
					page();
				}, "json");
				return true;
			}
		});
	}
</script>
<script id="adjustTpl" type="text/template">
	<div class="row" style="margin: 30px auto;">
		<div class="col-xs-12">
			<div class="form-group">
				<label class="control-label col-sm-2" title="">
					<span class="required ">*</span>${text('等级')}：<i class="fa icon-question hide"></i></label>
				<div class="col-sm-10">
					<% var types = [{type:'VIP会员'},{type:'间接客户'},{type:'直接客户'}]; %>
					<#form:select id="type" class="form-control" items="${types}" itemLabel="type" itemValue="type" blankOption="true" blankOptionLabel="请选择"/>
				</div>
			</div>
		</div>
	</div>
</script>